<?php
$caption = BUtils::T('special_offer_list_lbl');
$this->pageTitle = Yii::app()->name . ' - ' . $caption;

$create_long_special_btn = BUtils::T('special_create_plan_btn');
$list_template_btn = BUtils::T('template_list_view_lbl');
$all_lbl = BUtils::T('all_op_lbl');

//get url_offer_img
$url_offer_img = empty($model[0]['url_offer_img']) ? 
	Yii::app()->request->baseUrl . '/images/default_special_picture.png' : str_replace('thumb_', '', $model[0]['url_offer_img']);
?>

<div id="chart" style="width:800px; height:600px; margin:0 auto"></div>
<script type="text/javascript">
$(function() {
	$('#chart').highcharts({
		chart: {
			type: 'line',
			marginRight: 130,
            marginBottom: 25
		},
		title: {
			text: 'Marketing reports',
			x: -20 //center
		},
		subtitle: {
			text: '15.05.2013 - 30.06.2013',
			x: -20
		},
		xAxis: {
			categories: ["18.05","20.05","21.05","26.05","27.05","28.05"],
			type: 'datetime',
			tickInterval: 7
		},
		yAxis: {
			min: -5,
			title: {
				text: 'Number of people'
			},
			allowDecimals: false,
			plotLines: [{
				value: 10,
				width: 2,
				color: '#00aaee'
			}]
		},
		tooltip: {
			valueSuffix: ''
		},
		legend: {
			layout: 'vertical',
			align: 'right',
			verticalAlign: 'top',
			x: -10,
			y: 100,
			borderWidth: 0
		},
		series: [{
			name: 'Reach',
			data: [2,6,11,13,17,20]		}, {
			name: 'Clicks',
			data: [1,3,5,6,8,9]		}, {
			name: 'Notifications',
			data: [0,0,1,1,1,2]		}, {
			name: 'Redeems',
			data: [0,0,0,0,0,0]		}]
	});
});
</script>

<div class="container prepend-top">
	<?php echo CHtml::button('< ' . BUtils::T('back_btn'), array('class'=>'button', 'onclick'=>"history.go(-1)")); ?>
</div>

<div class="container prepend-top append-bottom">
	
	<div class="span-17">
		<div class="box_white">
			<div class="biz-form">
				<div class="margin">
					<div class="right">
						<?php echo CHtml::link("<span>{$create_long_special_btn}</span>", Yii::app()->createUrl('/special/form'), array('class'=>'button button-huge button-compliment', 'title'=>BUtils::T('special_create_plan_eg'))) ?>
					</div>
					<div style="overflow:hidden;">
						<h3><?php echo $caption; ?></h3>
						<div class="tips"><?php echo BUtils::T('special_offer_list_eg'); ?></div>
					</div>
					<div class="clear"></div>
				</div>
				
				<div class="fieldswrap">
					<div class="fields mobile" style="text-align:right;">
<?php
echo CHtml::form(Yii::app()->createUrl($this->id.'/'.$this->action->id), 'post', array('id'=>'search_form'));
echo CHtml::dropDownList('filter_week', '', BUtils::WeekDayKeys(7), array('empty'=>$all_lbl)) . '<span class="space-1"></span>';
echo CHtml::dropDownList('filter_status', '', BUtils::SpecialStatus(), array('empty'=>$all_lbl)) . '<span class="space-1"></span>';
echo CHtml::dropDownList('filter_date', '', BUtils::SpecialValidStatus(), array('empty'=>$all_lbl)) . '<span class="space-1"></span>';
echo CHtml::ajaxSubmitButton(BUtils::T('search_btn'), null, array('beforeSend'=>'beforeSend', 'success'=>'success'), array('class'=>'button button-huge button-confirm button-thin'));
echo CHtml::endForm();
?>
					</div>
					<div class="mobile">
						<div id="loading-bar" style="text-align:center; margin:20px 0;">
							<img src="<?php echo Yii::app()->baseUrl; ?>/images/loader-bar.gif" />
						</div>
<div id="special-list">
</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<div class="span-7 right last">
		<div class="box_white append-bottom">
			<div class="biz-form margin">
				<h3><?php echo BUtils::T('default_offer_pciture_lbl'); ?></h3>
				<div>
					<img id="img_offer" src="<?php echo $url_offer_img; ?>" alg="offer picture" style="width:100%;" />
				</div>
<div>
<?php $this->widget('ext.EAjaxUpload.EAjaxUpload', array(
	'id' => 'uploadOfferImage',
	'config' => array(
		'buttonName' => BUtils::T('upload_new_picture_eg'),
		'action' => Yii::app()->createUrl('/merchant/uploadOfferImage'),
		'allowedExtensions'=>array("jpg","jpeg","gif","png"),
		'sizeLimit'=>8*1024*1024,
		'onComplete' => "js:function(id, fileName, responseJSON){ handleUploadedOffer(responseJSON); }",
	),
)); ?>
</div>
				<div class="tips"><?php echo BUtils::T('default_offer_pciture_eg'); ?></div>
			</div>
		</div>
		<div class="box_white append-bottom" style="display:none">
			<div class="biz-form margin">
				<h3><?php echo BUtils::T('template_offer_lbl'); ?></h3>
				<div class="tips"><?php echo BUtils::T('template_offer_eg'); ?></div>
				<hr />
				<div class="">
					<?php echo CHtml::link("<span>{$list_template_btn}</span>", Yii::app()->createUrl('/specialTemp/index'), array('class'=>'button button-confirm')) ?>
				</div>
			</div>
		</div>
		<div class="box_white append-bottom">
			<div class="biz-form margin">
				<h3><?php echo BUtils::T('how_does_it_work_lbl'); ?></h3>
				<div class="tips"><?php echo BUtils::T('how_special_works_eg'); ?></div>
				<ol class="line">
					<li><?php echo BUtils::T('how_special_works_t1'); ?></li>
					<li><?php echo BUtils::T('how_special_works_t2'); ?></li>
					<li><?php echo BUtils::T('how_special_works_t3'); ?></li>
				</ol>
			</div>
		</div>
		<?php BHelper::HtmlCompletionTips(); ?>
	</div>
</div>
<script type="text/javascript">
$(function() {
	$.ajax({
		'beforeSend':beforeSend, 'success':success,
		'type':'POST', 'url':location.href, 'data':$('#search_form').serialize()
	});
	$('.special_counts a.label').click(function(){
		$('#search_form option').removeAttr('selected');
		var i = $(this).data('index');//find option index
		$('#filter_date option').eq(i).attr('selected', 'selected').trigger('change');
	});
	$('#search_form select').change(function(){
		$.ajax({
			'beforeSend':beforeSend, 'success':success,
			'type':'POST', 'url':location.href, 'data':$('#search_form').serialize()
		});
	});
});
function beforeSend() {
	$("#loading-bar").show();
	$("#special-list").html('');
}
function success(html) {
	$("#loading-bar").hide();
	$("#special-list").html(html);
}
function beforeRedeem() {
	$("#redeem-reply").html('<img src="<?php echo Yii::app()->baseUrl; ?>/images/loader-bar.gif" />');
}
function afterRedeem(html) {
	$("#redeem-reply").html(html);
}


function handleUploadedOffer(respJSON) {
	if (respJSON.error) {
		$('.qq-upload-button').html('<span>'+respJSON.error+'</span>');
	} else {
		if (respJSON.url_offer_img) {
			$('#img_offer').attr('src', respJSON.url_offer_img);
			$('ul.qq-upload-list').delay(1000).html('');
		}
	}
}
</script>